package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.ReportTypeBean;
import cn.bocweb.spinning.view.common.MyAdapter;

/**
 * Created by chenchangxing on 16/6/7.
 */
public class ReportTypeAdapter extends MyAdapter<ReportTypeBean.DataBean> {

    int selection = 1000;

    public ReportTypeAdapter(Context context, List<ReportTypeBean.DataBean> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_select_community, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }

        holder.mSelectCommunityTitle.setText(list.get(position).getTitle());

        if (selection == position) {
            holder.mWriteQuizCommunity.setBackgroundResource(R.drawable.bg_blue);
            holder.mSelectCommunityTitle.setTextColor(context.getResources().getColor(R.color.white));
        } else {
            holder.mWriteQuizCommunity.setBackgroundResource(R.drawable.bg_white_press);
            holder.mSelectCommunityTitle.setTextColor(context.getResources().getColor(R.color.content));
        }

        return convertView;
    }

    public void setSelection(int selection) {
        this.selection = selection;
    }

    static class ViewHolder {
        @Bind(R.id.select_community_title)
        TextView mSelectCommunityTitle;
        @Bind(R.id.write_quiz_community)
        RelativeLayout mWriteQuizCommunity;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
